package yuan.common;


import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Histogram;

import java.util.Random;

public class MyHistogram {

    public static Histogram histogramRequestLatency = Histogram.build("requests_latency_seconds", "Request latency in seconds.")
            .buckets(.0, .005, .010, .020, .040, .080, 0.1)
//            .name("requests_latency_seconds")
//            .help("Request latency in seconds.")
            .labelNames("method", "endpointURL", "status").register(new CollectorRegistry(true));


    public static double test(){

        Histogram.Child child = histogramRequestLatency.labels("test", "endpointURL", "ok");
        Histogram.Timer timer = child.startTimer();
        try {
            Random random = new Random();
            int i = random.nextInt(100);
            Thread.sleep(i);
            System.out.println(i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return timer.observeDuration();

    }



}
